package com.tuo51.childcare.controller;

import com.tuo51.childcare.domain.photoalbum.PhotoAlbum;
import com.tuo51.childcare.service.PhotoAlbumService;
import com.tuo51.core.domain.staffs.Staff;
import com.tuo51.foudation.model.MemVerificationCache;
import com.tuo51.foudation.model.StatusResponse;
import com.tuo51.foudation.query.base.PagerQuery;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.tuo51.foudation.constant.RequestConstant.TICKET;


@RestController
@RequestMapping("/papi/photo_album")
@Slf4j
@Api(value = "/papi/photo_album", tags = "家长服务号 - 时光相册")
public class PapiPhotoAlbumController {

    @Autowired
    private PhotoAlbumService photoAlbumService;

    @Autowired
    private MemVerificationCache cache;

    @RequestMapping("/albums")
    public StatusResponse childrenAlbumPage(@RequestHeader(TICKET) String ticket, String childrenId, PagerQuery pagerQuery ){
        Staff staff = cache.getStaff(ticket);

        Page<PhotoAlbum> page = photoAlbumService.childrenAlbumPage(childrenId, pagerQuery);

        return StatusResponse.success(page);
    }

    @RequestMapping("/detail")
    public StatusResponse albumDetail(@RequestHeader(TICKET) String ticket, String albumId ){
        Staff staff = cache.getStaff(ticket);
        PhotoAlbum album = photoAlbumService.photoAlbumById(albumId);
        return StatusResponse.success(album);
    }

    @RequestMapping("/create")
    public StatusResponse createAlbum(@RequestHeader(TICKET) String ticket, String childrenId, String jsonStr){
        Staff staff = cache.getStaff(ticket);

        PhotoAlbum album = photoAlbumService.createPhotoAlbum(childrenId, null, null, jsonStr);

        return StatusResponse.success(album);
    }

    @RequestMapping("/all_valid_photos")
    public StatusResponse addLiveRecord(@RequestHeader(TICKET) String ticket, String childrenId, PagerQuery pagerQuery ){
        Staff staff = cache.getStaff(ticket);
        Page<String> phtotos = photoAlbumService.getAllValidPhotoURL(childrenId, null, pagerQuery);
        return StatusResponse.success(phtotos);
    }

    @RequestMapping("/album_templates")
    public StatusResponse getAlbumTemplates(@RequestHeader(TICKET) String ticket, PagerQuery pagerQuery ){
        Staff staff = cache.getStaff(ticket);
        List templates = photoAlbumService.getAllTemplates(null);
        return StatusResponse.success(templates);
    }

    @RequestMapping("/album_template_pages")
    public StatusResponse getAlbumTemplatePages(@RequestHeader(TICKET) String ticket, String templateId ){
        Staff staff = cache.getStaff(ticket);
        List pages = photoAlbumService.getAllTemplatePages(templateId);
        return StatusResponse.success(pages);
    }
}
